package kr.co.doriclassic.mypuppystory.infopuppy;


import java.util.ArrayList;

import kr.co.doriclassic.mypuppystory.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	Context context;
	int layout;
	ArrayList<Item> itemList;
	LayoutInflater inflater;
	String search;

	public MyAdapter(Context context, int layout, ArrayList<Item> itemList) {
		this.context = context;
		this.layout = layout;
		this.itemList = itemList;
		inflater = LayoutInflater.from(context);
	}
	public MyAdapter(Context context, int layout, ArrayList<Item> itemList, String search) {
		this.context = context;
		this.layout = layout;
		this.itemList = itemList;
		this.search = search;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return itemList.size();
	}

	@Override
	public String getItem(int position) {
		return itemList.get(position).getSub();
	}
	
	//getitemid - position
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	//속도를 빠르게 전개하기 위해 뷰홀더 쓴다. 레이어 안의 객체
	class ViewHolder {
		TextView sub;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View itemLayout = convertView;
		ViewHolder viewHolder = null;
		//처음 생성되었을 때, 나머지는 재활용(리스트뷰)
		if (itemLayout == null) {
			
			itemLayout = inflater.inflate(layout, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.sub = (TextView) itemLayout
					.findViewById(R.id.label);
			itemLayout.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) itemLayout.getTag();
		}
		
		viewHolder.sub.setText(itemList.get(position).getSub());
		
		return itemLayout;
	}
}
